﻿@using Freesql.Tool.Helpers;
@using Freesql.Tool.Models;
@using System.Collections.Generic;
@{
    var gen = Model as Freesql.Tool.Models.RazorTemplateModel;
    var list = new List<Property>();
    var isEnum = false;
    var classPath = $"{gen.NameSpace}.Domain.Entities.{gen.TableName}";
    list = ReflectionHelper.GetProperties(classPath, true, out isEnum);
    var description = ReflectionHelper.GetDescription(classPath);
    var enums = list.Where(p => p.IsEnum == true).Select(p => p.Name).ToArray();
    var import = string.Join(",", enums);
    string ToLowerFirst(string str)
    {
        return str.Substring(0, 1).ToLower() + str.Substring(1);
    }

}
import type { FormSchema } from '@@/components/core/schema-form/';
import Api from '@@/api';
import { @(import) } from '@@/enums';

export const @(gen.LowerTableName)Schemas: FormSchema<@(gen.TableName)Out>
    [] = [
    @foreach (var item in list)
    {
        @("{")
        @($"field: '{ToLowerFirst(item.Name)}',")
        @($"component: '{item.Component}',")
        @($"label: '{item.Description}',")
        @("rules: [{ required: "+item.Required+" }],")

            if (item.IsEnum)
            {
                var temp = @"
componentProps: { options: [
    #options#
]}";
                var options = "";
                foreach (var enumItem in item.EnumInfos)
                {
                    var itemTemp = @"{ label: '#name#',value: #value# }";
                    var index = item.EnumInfos.IndexOf(enumItem);
                    if (index != item.EnumInfos.Count - 1){
                        itemTemp += @",
    ";
                    }
                    options += itemTemp.Replace("#name#", enumItem.Desc).Replace("#value#", enumItem.Name);
                }
                temp = temp.Replace("#options#", options);
@(temp)
            }
        @("},")
        @:
    }
];
